﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OracleClient;

namespace BLL.StatSheme
{
    public class detailScheme
    {
        OracleDAL.StatSheme.detailScheme osd = new OracleDAL.StatSheme.detailScheme();
        BLL.ResourceManage.ResourceBase rrb = new BLL.ResourceManage.ResourceBase();
        /// <summary>
        ///  得到统计数目列表显示
        /// </summary>
        /// <param name="tablename">资源表名称</param>
        /// <param name="nodetype">节点类型</param>
        /// <param name="nodeid">节点值</param>
        /// <param name="strLevel">级别码</param>
        /// <param name="schemeid">项目编号</param>
        /// <returns></returns>
        /// 
        #region 得到统计数目列表显示
        public DataSet getdetail(string tablename, string nodetype, string nodeid, string strLevel, string schemeid)
        {
            string sql = "select CHFIELD,ENFIELD,VALUETYPE from  cfg_resource_fields where tablename='" + tablename + "'";
            string tableN = "";
            string strFiled = "";
            DataSet dsWhere = new DataSet();
            string strWhere = "";
            string[] strArr;
            string[] strTemp = { "and" };
            DataSet ds = new DataSet();
            rrb.getResQVTName(tablename);

            if (rrb.getTableName() == rrb.getViewName())
            {
                tableN = rrb.getTableName();
            }
            else
            {
                tableN = rrb.getViewName();
            }


            sql = "select  statcondition ,stattype  from com_statistics_sheme_operate where levelcode='" + strLevel + "' and shemeid='" + schemeid + "'";
            dsWhere = osd.getDs(sql);
            if (dsWhere.Tables[0].Rows.Count != 0)
            {
                if (dsWhere.Tables[0].Rows[0]["stattype"].ToString() != "stat,1")
                {
                    strWhere = dsWhere.Tables[0].Rows[0]["statcondition"].ToString();
                    strArr = strWhere.Split(strTemp, StringSplitOptions.None);
                    if (strArr.Length == 0)
                    {
                        strFiled = tableN + "." + strArr[0].ToString();
                    }
                    else
                    {
                        for (int i = 0; i < strArr.Length; i++)
                        {

                            strFiled += tableN + "." + strArr[i].ToString() + " and ";
                        }
                        //strWhere = strWhere.Substring(0, strWhere.Length - 4);


                    }

                    strWhere = " and " + strFiled + " " + tableN + "." + nodetype + " like '" + nodeid + "%'";

                }
                else
                {
                    strWhere = "";
                }
                dsWhere.Clear();
                dsWhere.Dispose();
                sql = rrb.getCommonResource(tablename, "", strWhere, "", "");
                ds = osd.getDs(sql);

            }
            return ds;
        }
        #endregion
       
    }
}
